package vista;

import com.gestion.modelo.dominio.Pedido;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.event.ListSelectionListener;
import vista.modelo.ModeloTablaPedido;

/**
 *
 * @author Mauri@<itsoluciones.com.ar>
 */
public class JIFListadoPedidos extends javax.swing.JInternalFrame {

    //private TableRowSorter<ModeloTablaPedido> sorter; //Para que es esto?
    //private JDesktopPane jDesktopPane1 = null; //para que esto?
    /**
     * Creates new form JIFListadoPedidos
     */
    public JIFListadoPedidos() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTListadoPedidos = new javax.swing.JTable();
        jBListar = new javax.swing.JButton();
        jBCerrar = new javax.swing.JButton();

        jTListadoPedidos.setModel(new vista.modelo.ModeloTablaPedido(new ArrayList<Pedido>()));
        jScrollPane1.setViewportView(jTListadoPedidos);

        jBListar.setText("Listar");

        jBCerrar.setText("Cerrar");
        jBCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCerrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jBCerrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBListar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBListar)
                    .addComponent(jBCerrar)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCerrarActionPerformed
        this.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_jBCerrarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCerrar;
    private javax.swing.JButton jBListar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTListadoPedidos;
    // End of variables declaration//GEN-END:variables
//"Escuchador de Listar el Pedido Seleccionado

    //<editor-fold defaultstate="collapsed" desc="Relacionado con los Listeners de Botones">
    
    public void agregarListarPedidosListener(ActionListener listarPedidoListener) {
        this.jBListar.addActionListener(listarPedidoListener);
    }//</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Relacionado con la Tabla de Pedidos">
    public void agregarSeleccionaPedidoListener(ListSelectionListener pedidoSeleccionadoListener) {
        this.jTListadoPedidos.getSelectionModel().addListSelectionListener(pedidoSeleccionadoListener);
    }

    public void agregarPedidosTabla(List<Pedido> pedidos) {
        ((ModeloTablaPedido) this.jTListadoPedidos.getModel()).setListaPedido(pedidos);
    }

    public Object getPedidoIdSeleccionado() {
        int indice = this.jTListadoPedidos.getSelectedRow();
        Object valueAt = this.jTListadoPedidos.getModel().getValueAt(indice, 0);
        //System.out.println("indice"+ indice);
        return valueAt;
    }//</editor-fold>
}
